package net.qiqb.execute;

import lombok.extern.slf4j.Slf4j;
import net.qiqb.core.executing.annotation.Command;
import net.qiqb.core.executing.annotation.HandleBusiness;
import net.qiqb.core.executing.annotation.ObtainAggregateObject;
import net.qiqb.core.executing.annotation.PersistAggregateObject;

@Command(User.class)
@Slf4j
public class CreateUserCmd {

    private final String userName;

    public CreateUserCmd(String userName) {
        this.userName = userName;
    }

    /**
     * 加载器
     *
     * @return
     */
    @ObtainAggregateObject
    public User obtainUser() {

        final User user = new User(new UserId("123"), this.userName);
        log.info("创建用户聚合根：{}", user.getUserName());
        return user;
    }


    @HandleBusiness
    public void handle(User user) {
        log.info("创建用户命令处理逻辑：" + user.getUserName());
    }

    @PersistAggregateObject
    public void persist(User newUser, User oldUser) {
        log.info("用户聚合根持久话：" + newUser.getUserName());
    }
}
